//
//  ACFileListCell.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/30.
//

#import "ACFileListCell.h"

@interface ACFileListCell ()
@property (weak, nonatomic) IBOutlet UIImageView *fileCover;
@property (weak, nonatomic) IBOutlet UILabel *fileTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *uploadTime;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;
@property (weak, nonatomic) IBOutlet UIImageView *fileType;
@property (nonatomic, assign)NSInteger styleIndex;
@end

@implementation ACFileListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.fileType.layer.masksToBounds = YES;
    self.fileCover.layer.cornerRadius = 4;
    
    self.deleteBtn.layer.masksToBounds = YES;
    self.deleteBtn.layer.cornerRadius = 14;
    self.deleteBtn.layer.borderWidth = 1;
}
- (IBAction)deleteBtnAction:(id)sender {
    UIButton *button = (UIButton *)sender;
    if (self.styleIndex == 3) {
        [button setSelected:!button.isSelected];
        if (self.clickActionHandler) {
            self.clickActionHandler(button.isSelected);
        }
    }else{
        if (self.clickActionHandler) {
            self.clickActionHandler(0);
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



-(void)setBtnStyle:(int )styleIndex{
    self.styleIndex = styleIndex;
    if (styleIndex == 0) {
        self.deleteBtn.layer.borderColor = UIColorFromRGB(0xE2E1E0).CGColor;
        [self.deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [self.deleteBtn setTitleColor:UIColorFromRGB(0x909399) forState:UIControlStateNormal];
        [self.deleteBtn setBackgroundColor:UIColorFromRGB(0xFFffff)];
    }else if (styleIndex == 1){
        [self.deleteBtn setTitle:@"切换" forState:UIControlStateNormal];
        [self.deleteBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        self.deleteBtn.layer.borderColor = UIColorFromRGB(0xFF6048).CGColor;
        [self.deleteBtn setBackgroundColor:UIColorFromRGB(0xFF6048)];
    }else if (styleIndex == 2){
        [self.deleteBtn setTitle:@"查看" forState:UIControlStateNormal];
        [self.deleteBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        self.deleteBtn.layer.borderColor = UIColorFromRGB(0xFF6048).CGColor;
        [self.deleteBtn setBackgroundColor:UIColorFromRGB(0xFF6048)];
    }else if (styleIndex == 3){
        [self.deleteBtn setTitle:@"" forState:UIControlStateNormal];
        [self.deleteBtn setImage:[UIImage imageWithName:@"icon_live_type_select" bundle:ACLiteAVUISDK targetClass:[self class]] forState:UIControlStateSelected];
        [self.deleteBtn setImage:[UIImage imageWithName:@"icon_live_type_noSelect" bundle:ACLiteAVUISDK targetClass:[self class]] forState:UIControlStateNormal];
        self.deleteBtn.layer.borderColor = UIColor.whiteColor.CGColor;
    }
}

-(void)setFileModel:(ACFileModel *)fileModel{
    _fileModel = fileModel;
    self.fileTitleLabel.text = _fileModel.title;
    if ([_fileModel.file_extension isEqualToString:@"pdf"]) {
        self.fileType.image = [UIImage imageWithName:@"icon_live_fileType_pdf" bundle:ACLiteAVUISDK targetClass:[self class]];
    }else if ([_fileModel.file_extension isEqualToString:@"ppt"] || [_fileModel.file_extension isEqualToString:@"pptx"]){
        self.fileType.image = [UIImage imageWithName:@"icon_live_fileType_ppt" bundle:ACLiteAVUISDK targetClass:[self class]];
    }else if ([_fileModel.file_extension isEqualToString:@"jpg"] ||[_fileModel.file_extension isEqualToString:@"png"] ){
        self.fileType.image = [UIImage imageWithName:@"icon_live_fileType_img" bundle:ACLiteAVUISDK targetClass:[self class]];
    }
    self.uploadTime.text = [@"上传时间：" stringByAppendingString:_fileModel.created_at];
}

@end
